package com.leyou.service.impl;

import com.leyou.common.vo.SpuItemAttrGroupVo;
import com.leyou.entity.SpecParamEntity;
import com.leyou.service.SpecParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;



import com.leyou.dao.SpecGroupDao;
import com.leyou.entity.SpecGroupEntity;
import com.leyou.service.SpecGroupService;


@Service("specGroupService")
public class SpecGroupServiceImpl extends ServiceImpl<SpecGroupDao, SpecGroupEntity> implements SpecGroupService {

    @Autowired
    SpecParamService specParamService;

    @Autowired
    SpecGroupDao specGroupDao;
    @Override
    public List<SpecGroupEntity> listByCid(Long cid) {
        return this.list(new QueryWrapper<SpecGroupEntity>().eq("cid",cid));
    }

    /**
     * 根据分类id  获取属性分组及分组下的所有属性
     *
     * @param cid
     * @return
     */
    @Override
    public List<SpuItemAttrGroupVo> getGroupAttrByCid(Long cid) {
        return specGroupDao.getGroupAttrByCid(cid);
    }

    @Override
    public boolean deleteSpec(Long id) {
        /**
         * TODO  删除之前还要判断一下该分组下是否还有销售属性
         */
        List<SpecParamEntity> paramEntities = specParamService.listByGid(id);
        if(paramEntities != null && paramEntities.size()>0){
            return false;
        }else {
            this.removeById(id);
            return true;
        }

    }
}